<?php

require_once './include/common.inc.php';

getMyParam('categoryid');

if (!is_numeric($categoryid) || $categoryid <= 0) {
    header("Location:photo.php");
    exit;
}

$page_title = 'jans2en furniture - Photo Gallery - Photo Gallery';
$menu_id = 3;


// *** page code start ***
$page_url = 'photo_view.php?categoryid=' . $categoryid . '&';
$sql = "SELECT `id`, `name`, `pic` FROM `photo` WHERE `photo_category_id`=$categoryid AND `type`=0";
$query = $db->query($sql);
$sql_all_num = $db->num_rows($query);

$ppp = 12;
getMyParam('page');
$page = empty($page) || !ispage($page) ? 1 : $page;
$start_limit = ($page - 1) * $ppp;
if($start_limit > $sql_all_num) {
    $start_limit = 0;
    $page = 1;
}

$page_show = getPhotoPageStr($sql_all_num, $page, $ppp, $page_url);
// *** page code end ***

$photo_ary = array();
$sql = "SELECT `id`, `name`, `pic` FROM `photo` WHERE `photo_category_id`=$categoryid  AND `type`=0 ORDER BY `seq` ASC, `id` DESC LIMIT $start_limit, $ppp";
$query = $db->query($sql);
while($rs = $db->fetch_array($query)) {
    $photo_ary[] = array('id'=>$rs['id'], 'name'=>$rs['name'], 'pic'=>$rs['pic']);
}

$photo_category_ary = array();
$sql = "SELECT `id`, `name` FROM `photo_category` ORDER BY `seq` ASC, `id` DESC";
$query = $db->query($sql);
while($rs = $db->fetch_array($query)) {
    $photo_category_ary[$rs['id']] = $rs['name'];
}

$select_str = '';
foreach ($photo_category_ary as $k=>$v) {
    $selected = "";
    if ($k == $categoryid) {
        $selected = "selected";
    }
    $select_str .= '<option value="' . $k . '" ' . $selected . '>' . $v . '</option>';
}

	browseTracking(13,0,'Photo Gallery > '.$photo_category_ary[$categoryid].'(page '.$page.')');
	
require_once PrintEot('header');
require_once PrintEot('photo_view');
require_once PrintEot('footer');

?>